// Person.java
//
// Informatics 102 Spring 2012
// Code Example
//
// The interesting thing about this Person class is that its toString()
// method's result is to be cached for one second.  That means if the
// toString() method is called on a particular Person more than once
// within a second, the second and subsequent calls will use the previous
// result, rather than recalculating it.
//
// As a practical matter, a simple toString() method like this one is
// probably not worth caching in most circumstances, unless it will be used
// often.  But this technique would be especially useful if, for example, a
// method needed to connect to a database or a web service in order to fetch
// its result.

public class Person
{
	private String socialSecurityNumber;
	private String name;
	private String phoneNumber;
	
	
	public Person(String socialSecurityNumber, String name, String phoneNumber)
	{
		this.socialSecurityNumber = socialSecurityNumber;
		this.name = name;
		this.phoneNumber = phoneNumber;
	}
	
	
	public void setName(String newName)
	{
		name = newName;
	}
	
	
	@Cached(timeToLiveMillis = 1000)
	public String toString()
	{
		return "Person: " + name + " (SSN=" + socialSecurityNumber
			+ ") (Phone=" + phoneNumber + ")";
	}
}
